<?php

###########################################################################
#   Copyright (C) 2012 CDNPAL LTD by Christopher Gu                       #
#   resources@cdnpal.com                                                  #
#                                                                         #
#   coded for Php 4.3/5.X and above                                       #
#   and AllowOverride all for .htaccess                                   #
#                                                                         #
#   This program is free software released                                #
#   under the GPL version 2 license:                                      #
#   http://www.gnu.org/licenses/gpl-2.0.htm                               #
#                                                                         #
#   This program is distributed WITHOUT ANY WARRANTY                      #
#   or FITNESS FOR A PARTICULAR PURPOSE.                                  #
#                                                                         #
#   DADF-SDK                                                              #
#                                                                         #
###########################################################################

class IncomingBidRequest extends GenericDataObject
{
    protected $_primary = 'IncomingBidRequestID';
	protected $_name = 'IncomingBidRequest';
    
	public $class_member_only_incoming_request_partner;
	
	public $class_member_only_incoming_request_adbundle_list = array();
	
	public $class_member_only_incoming_request_authentication;
	
	public function add_incoming_request_adbundle($request_adbundle) {
	
		$this->class_member_only_incoming_request_adbundlelist[] = $request_adbundle;
	}
	
	public function load_children() {
		
		$incoming_request_adbundle_factory = IncomingRequestAdbundleFactory::get_instance();
		
		$params = array();
		$params["IncomingBidRequestID"] = $this->IncomingBidRequestID; 
		$incoming_request_adbundle_list = $incoming_request_adbundle_factory->get($params);

		foreach ($incoming_request_adbundle_list as $incoming_request_adbundle):
		
			$incoming_request_adbundle->load_children();
			$this->class_member_only_incoming_request_adbundle_list[] = $incoming_request_adbundle;
		
		endforeach;
		
		$incoming_request_authentication_factory = IncomingRequestAuthenticationFactory::get_instance();
		$this->class_member_only_incoming_request_authentication = $incoming_request_authentication_factory->get_row($params);
		
	}
	
	/*
	 * TODO: All all the save_children functions
	 */
	
	public function save_children() {
	
		foreach ($this->class_member_only_incoming_request_adbundle_list as $incoming_request_adbundle):
	
			$incoming_request_adbundle->save();
			$incoming_request_adbundle->save_children();
		
		endforeach;
	
		if ($this->class_member_only_incoming_request_authentication != null):
			$this->class_member_only_incoming_request_authentication->save();
		endif;
		
	}
	
}

